<?php

use console\db\channels\TransferTableMigration;

/**
 * 旧系统圈子表迁移
 * 
 * @author emhome <emhome@163.com>
 * @since 1.0
 */
class m300020_000002_t_sns_group extends TransferTableMigration {

    /**
     * @inheritdoc
     */
    public $sourceDb = 'olddb';

    /**
     * @inheritdoc
     */
    public function validateTransfer(&$data) {
        if (parent::validateTransfer($data)) {
            if ($data['status'] > 0) {
                return true;
            }
        }
        return false;
    }

    /**
     * @inheritdoc
     */
    public function getTransferOptions() {
        return [
            'table' => [
                'sns_group' => 'sns_group',
            ],
            'columns' => [
                'id' => 'gid',
                'name',
                'brand' => function($data) {
                    if ($data['logo']) {
                        if (strpos($data['logo'], 'http') !== false) {
                            return $data['logo'];
                        }
                        return '/uploads/' . ltrim($data['logo'], '/');
                    }
                    return '';
                },
                'description' => 'info',
                'type_id' => 'cid',
                'official' => 'isadmin',
                'status' => function($data) {
                    return $data['status'] > 0 ? 10 : 0;
                },
                'created_at' => function($data) {
                    if ($data['createtime']) {
                        return $data['createtime'];
                    }
                    return time();
                },
                'updated_at' => function() {
                    return time();
                },
            ],
        ];
    }

}
